package com.central.operate.service.impl;

import com.central.model.common.PageResult;
import com.central.model.common.utils.PageUtil;
import com.central.operate.dao.RegisterDao;
import com.central.operate.dto.ChartParams;
import com.central.operate.model.LoginCreateTime;
import com.central.operate.model.LoginInfo;
import com.central.operate.model.OperateRecord;
import com.central.operate.service.RegisterService;
import com.central.operate.vo.RegisterCountChartVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    private RegisterDao registerDao;

    @Override
    public PageResult<LoginInfo> getSpecificRegisterTime(Map<String, Object> params) {
        PageUtil.pageParamConver(params, true);
        int total = registerDao.registerCount(params);
        List<LoginInfo> list = Collections.emptyList();
        if (total > 0) {
            list = registerDao.findRegisterList(params);
        }
        return PageResult.<LoginInfo>builder().data(list).code(0).count((long) total).build();
    }

    @Override
    public PageResult<LoginCreateTime> findLoginRegister(Map<String, Object> params) {
        PageUtil.pageParamConver(params, true);
        List<Integer> size = registerDao.findRegisterCount();
        List<LoginCreateTime> list = registerDao.findRegister(params);
        return PageResult.<LoginCreateTime>builder().data(list).code(0).count(size.size() + 0L).build();
    }

    @Override
    public Integer findRegisterOneHour(Map<String, Object> params) {
        return registerDao.registerCount(params);
    }

    @Override
    public List<RegisterCountChartVO> listRegisterCount(Map<String, Object> params) {
//        if (params.get("start_time") == null || params.get("start_time") == "") {
//            Date date = new Date();
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//            params.put("start_time",sdf.format(date));
//        }
//        if (params.get("consecutive_day") == null || params.get("consecutive_day") == ""){
//            params.put("consecutive_day","7");
//        }
//        if (params.get("interval_hour") == null || params.get("interval_hour") == ""){
//            params.put("interval_hour","1");
//        }
        ChartParams chartParams = new ChartParams(params);
        log.info(chartParams.toString());
        return registerDao.listRegisterCount(chartParams);
//        return registerDao.listRegisterCount(params);
    }
}
